/**
 * Created by acer1 on 2017/8/6.
 *//*上传图片到阿里并返回url*/

var client = new OSS.Wrapper({//新建一个对象存储对象
    region : 'oss-cn-beijing',//对象存储（数据中心）所在地
    accessKeyId : 'LTAIJWjMhY4pWJw4',//申请的akID
    accessKeySecret : 'XUPmliAxUREWNu9bv1ORUv9Iq0scCB',//申请的ak密码
    bucket : 'senmiao1'//oss对象存储文件夹的名字
});


$('.file').on('change',function(){
    var f = $(this)[0].files[0];
    var val= $(this).val();
    var suffix = val.substr(val.indexOf("."));
    var obj=timestamp();
    var storeAs = 'upload-file/'+obj+suffix;

    client.multipartUpload(storeAs, f).then(function (result) {
        $(this).parent().prev('img').attr('src',result.url);

    }).catch(function (err) {
        console.log(err);
    });
});


function timestamp(){
    var time = new Date();
    var y = time.getFullYear();
    var m = time.getMonth()+1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return ""+y+add0(m)+add0(d)+add0(h)+add0(mm)+add0(s);
}

function add0(m){//判断‘月’前面是否加0
    return m<10?'0'+m : m;
}

